//
//  ChooseWayCell.m
//  IpadTestB
//
//  Created by edianzu on 2017/7/5.
//  Copyright © 2017年 ruilai. All rights reserved.
//

#import "ChooseWayCell.h"
@interface ChooseWayCell()
@property(nonatomic,copy)NSIndexPath * indexp;
@property(nonatomic,strong)NSMutableArray * scArray;
@end
@implementation ChooseWayCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createUI];
    }
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    return self;
}

-(void)createUI{
    
    self.choseWayLabel = [[UILabel alloc]init];
    self.choseWayLabel.textColor = [UIColor blackColor];
    self.choseWayLabel.font = [UIFont boldSystemFontOfSize:23*AutoScaleHorizontal];
    self.choseWayLabel.text = @"选择范围";
    [self.choseWayLabel setTextAlignment:NSTextAlignmentCenter];
    [self.contentView addSubview:self.choseWayLabel];
    [self.choseWayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contentView.mas_centerX);
        make.top.mas_equalTo(self.contentView.mas_top).with.offset(40*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(100*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    
    self.selectImage = [[UIImageView alloc]init];
    self.selectImage.image = [UIImage imageNamed:@"selectImg"];
    [self.contentView addSubview:self.selectImage];
    [self.selectImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).with.offset(25*AutoScaleHorizontal);
        make.top.mas_equalTo(self.choseWayLabel.mas_bottom).with.offset(40*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(25*AutoScaleHorizontal, 25*AutoScaleVertical));
    }];
    
    self.label = [[UILabel alloc]init];
    self.label.textColor = [UIColor blackColor];
    self.label.font = [UIFont systemFontOfSize:20*AutoScaleHorizontal];
    self.label.text = @"全选";
    [self.contentView addSubview:self.label];
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.selectImage.mas_right).with.offset(10*AutoScaleHorizontal);
        make.top.mas_equalTo(self.selectImage.mas_top);
        make.size.mas_equalTo(CGSizeMake(80*AutoScaleHorizontal, 25*AutoScaleVertical));
    }];
    
    self.coverBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.coverBtn.backgroundColor = [UIColor clearColor];
    [self.coverBtn addTarget:self action:@selector(pressCover) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.coverBtn];
    [self.coverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(self.contentView);
    }];
    
}

//添加孩子第一行 全选项
-(void)relayoutCellWithIsAll:(NSString*)all{
    if ([all isEqualToString:@"1"]) {
        self.selectImage.image =[UIImage imageNamed:@"selectImgS"];
        self.coverBtn.selected = YES;
    }else{
        self.selectImage.image =[UIImage imageNamed:@"selectImg"];
        self.coverBtn.selected = NO;
    }
}

//添加孩子第一行  选择范围
-(void)relayoutCellWithIsAll:(NSString *)all andClassChoose:(ClassModel *)model andArray:(NSMutableArray *)array{
    self.scArray = [NSMutableArray arrayWithArray:array];
    [self.classChosenLabel removeFromSuperview];
    if ([all isEqualToString:@"1"]) {
        self.selectImage.image = [UIImage imageNamed:@"selectImgS"];
        self.coverBtn.selected = YES;
    }else{
        self.selectImage.image =[UIImage imageNamed:@"selectImg"];
        self.coverBtn.selected = NO;
    }
    
    self.classChosenLabel = [[UILabel alloc]init];
    self.classChosenLabel.layer.cornerRadius = 10;
    self.classChosenLabel.layer.borderWidth = 1;
    [self.classChosenLabel setTextAlignment:NSTextAlignmentCenter];
    self.classChosenLabel.text = model.Name;
    self.classChosenLabel.layer.borderColor = UIColorFromRGB(130, 130, 130).CGColor;
    [self.contentView addSubview:self.classChosenLabel];
    [self.classChosenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.choseWayLabel.mas_bottom).with.offset(15*AutoScaleVertical);
        make.centerX.mas_equalTo(self.contentView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(150*AutoScaleHorizontal, 40*AutoScaleVertical));
    }];
    
    self.classChosenIMG = [[UIImageView alloc]init];
    self.classChosenIMG.image = [UIImage imageNamed:@"arrowView"];
    [self.classChosenLabel addSubview:self.classChosenIMG];
    [self.classChosenIMG mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.classChosenLabel.mas_right).with.offset(-5*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.classChosenLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(15*AutoScaleHorizontal, 15*AutoScaleVertical));
    }];
    
    _classBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _classBtn.backgroundColor = [UIColor clearColor];
    [_classBtn addTarget:self action:@selector(pressClass) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_classBtn];
    [_classBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(self.classChosenLabel);
    }];
    
    [self.selectImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).with.offset(25*AutoScaleHorizontal);
        make.top.mas_equalTo(self.classChosenLabel.mas_bottom).with.offset(40*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(25*AutoScaleHorizontal, 25*AutoScaleVertical));
    }];
    
    [self.coverBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(self.contentView);
        make.top.mas_equalTo(self.selectImage.mas_top);
    }];
}

-(void)pressClass{
    NSLog(@"切换班级");
    self.callClass();
}
//开始测试第一行 测试项
-(void)relayoutPROJECTCell{
    [self.selectImage removeFromSuperview];
    [self.label removeFromSuperview];
    [self.coverBtn removeFromSuperview];
    self.choseWayLabel.text = @"测试项";
    [self.choseWayLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contentView.mas_centerX);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(130*AutoScaleHorizontal, 40*AutoScaleVertical));
    }];
}
-(void)pressCover{
    NSLog(@"cover");
//    self.callAll();
//    self.coverBtn.selected = !self.coverBtn.selected;
    if (self.coverBtn.selected ==YES) {
        self.selectImage.image =[UIImage imageNamed:@"selectImgS"];
        self.callAll(@"1");
    }else{
        self.selectImage.image =[UIImage imageNamed:@"selectImg"];
        self.callAll(@"0");
    }
    
}


//-()

@end











